package com.hqully.labmanage.controller;

import com.github.pagehelper.PageInfo;
import com.hqully.labmanage.domain.dto.DeviceDTO;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.vo.ResultVO;
import com.hqully.labmanage.service.DeviceService;
import com.hqully.labmanage.utils.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-08 11:16:28
 */
@Api(tags = {"设备数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/device")
public class DeviceController extends BaseController {

    @Resource
    private DeviceService deviceService;

    @ApiOperation(value = "分页条件查询设备列表")
    @GetMapping("/page-devices")
    public ResultVO<PageInfo<DeviceDTO>> pageDevices(PageDTO page, DeviceDTO deviceDTO) {
        PageInfo<DeviceDTO> devicePage = deviceService.pageDevices(page, deviceDTO);
        return ResultVOUtil.success(devicePage);
    }

    @ApiOperation(value = "条件查询设备列表")
    @GetMapping("/list-devices")
    public ResultVO<List<DeviceDTO>> listDevices(DeviceDTO deviceDTO) {
        List<DeviceDTO> deviceList = deviceService.listDevices(deviceDTO);
        return ResultVOUtil.success(deviceList);
    }

    @ApiOperation(value = "添加设备")
    @PostMapping("/add-device")
    public ResultVO<DeviceDTO> addDevice(@Validated @RequestBody DeviceDTO deviceDTO) {
        deviceService.addDevice(deviceDTO);
        return ResultVOUtil.success("添加设备成功");
    }

    @ApiOperation(value = "更新设备")
    @PostMapping("/update-device")
    public ResultVO<DeviceDTO> updateDevice(@Validated @RequestBody DeviceDTO deviceDTO) {
        deviceService.updateDevice(deviceDTO);
        return ResultVOUtil.success("更新设备成功");
    }

    @ApiOperation(value = "删除设备")
    @DeleteMapping("/delete-device/{id}")
    public ResultVO<DeviceDTO> deleteDevice(@PathVariable("id") String id) {
        deviceService.deleteDeviceById(id);
        return ResultVOUtil.success("删除设备成功");
    }

}

